//: Playground - noun: a place where people can play

import UIKit

var str = "Hello, playground"

//LeetCode
//第一题
/***
 Given nums = [2, 7, 11, 15], target = 9,
 
 Because nums[0] + nums[1] = 2 + 7 = 9,
 return [0, 1].
 ***/
class Solution {
    func twoSum(nums: [Int], _ target: Int) -> [Int] {
        var digitDict = [Int : Int]()
        for (index, value) in nums.enumerate() {
            if let matchIndex = digitDict[target - value] {
                return [matchIndex, index]
            }
            digitDict[value] = index
        }
        return [0, 0]
    }
}

var nums = [2, 7, 11, 13]
let target = 13
let result = Solution.init()
result.twoSum(nums, target)

